﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows;
using ControleRepresentanteSync.Application.Wizard;

namespace ControleRepresentanteSync.View.Wizard
{
    public class WizardViewModel : ViewModelBase, IWizardViewModel
    {
        public static readonly DependencyProperty CurrentPageProperty = 
            DependencyProperty.Register("CurrentPage", typeof(IWizardPageViewModel), typeof(WizardViewModel));
        public static readonly DependencyProperty CanGoBackProperty = 
            DependencyProperty.Register("CanGoBack", typeof(bool), typeof(WizardViewModel));
        public static readonly DependencyProperty IsFinishProperty = 
            DependencyProperty.Register("IsFinish", typeof (bool), typeof (WizardViewModel));

        private readonly ObservableCollection<IWizardPageViewModel> m_Pages;

        public WizardViewModel()
        {
            m_Pages = new ObservableCollection<IWizardPageViewModel>();
        }

        public IWizardPageViewModel CurrentPage
        {
            get { return (IWizardPageViewModel) GetValue(CurrentPageProperty); }
            set { SetValue(CurrentPageProperty, value); }
        }

        public IList<IWizardPageViewModel> Pages
        {
            get { return m_Pages; }
        }

        public bool CanGoBack
        {
            get { return (bool) GetValue(CanGoBackProperty); }
            set { SetValue(CanGoBackProperty, value); }
        }

        public bool IsFinish
        {
            get { return (bool)GetValue(IsFinishProperty); }
            set { SetValue(IsFinishProperty, value); }
        }

        public event EventHandler GoBack;
        public event EventHandler GoForward;
        public event EventHandler Cancel;
        public event EventHandler<WizardCloseEventArgs> Close;

        public void FireClose(bool result)
        {
            if (Close != null)
                Close(this, new WizardCloseEventArgs(result));
        }

        public void FireGoBack()
        {
            if (GoBack != null)
                GoBack(this, EventArgs.Empty);
        }

        public void FireGoForward()
        {
            if (GoForward != null)
                GoForward(this, EventArgs.Empty);
        }

        public void FireCancel()
        {
            if (Cancel != null)
                Cancel(this, EventArgs.Empty);
        }
    }

    public class WizardCloseEventArgs : EventArgs
    {
        public bool Result { get; private set; }

        public WizardCloseEventArgs(bool result)
        {
            Result = result;
        }
    }
}